package com.wangcang.widgetlibrary.media;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.tools.ScreenUtils;

import java.util.List;

public class SelectAdapter extends CommonAdapter<String> {
    private Context mContext;

    private OnItemSelectListener mOnItemSelectListener;

    public void setOnItemSelectListener(OnItemSelectListener onItemSelectListener) {
        this.mOnItemSelectListener = onItemSelectListener;
    }

    public SelectAdapter(Context context, List<String> imagePathList){
        super(context, R.layout.item_image, imagePathList);

        this.mContext = context;
    }

    @Override
    public void convert(final ViewHolder holder, final String path) {
        final ImageView imageView = holder.getView(R.id.item_image);


        //宽度设置为屏幕的1/3(GridView有3列)
        ViewGroup.LayoutParams params =  imageView.getLayoutParams();
        params.width = params.height = (ScreenUtils.getScreenWidth(mContext)) / 3;
        imageView.setLayoutParams(params);

        holder.loadImage(mContext, R.id.item_image, path);
        holder.getView(R.id.item_selected).setVisibility(View.GONE);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemSelectListener != null) {
                    mOnItemSelectListener.onItemSelect(path);
                }
            }
        });
    }
}